package com.nommon.tool;

public class Vector2D {
	private float x;
	private float y;
	
	
	public Vector2D(float x, float y) {
		this.x = x;
		this.y = y;
	}
	
	public float getLength(){
		return (float)(Math.sqrt(x*x + y*y));
	}
	
	
	/**
	 * set length = 1
	 */
	public void normalize(){
		float length = getLength();
		if (length != 0){
			scale(1/length);
		}
	}
	
	public float x(){
		return x;
	}
	public float y(){
		return y;
	}

	public void scale(float factor) {
		x *= factor;
		y *= factor;
	}
	
	public Vector2D clone(){
		return new Vector2D(x, y);
	}
}
